/**
 * 
 */
package com.objectdraw.server.tools;

import com.objectdraw.server.ObjectDrawServer;
import com.objectdraw.server.data.Action;
import com.objectdraw.server.tools.data.DrawingObject;

/**
 * Used to create server-side freehand objects.
 * 
 * @author Harrison
 *
 */
public class FreehandServerTool extends ServerTool {
	private DrawingObject dro = new DrawingObject();
	
	/**
	 * Initailize the tool
	 */
	public FreehandServerTool(){
		super();
		name = "freehand";
		dro.setColor("");
		dro.setTool(name);
	}
	/* (non-Javadoc)
	 * @see com.objectdraw.server.tools.ServerTool#addAction(com.objectdraw.server.data.Action)
	 */
	/**
	 * creates a new drawing object with the name: "freehand" and the coords provided in the action
	 */
	@Override
	public void addAction(Action act) {
		if(act != null){
			if("mouse".equalsIgnoreCase(act.getAction())){
				if("released".equalsIgnoreCase(act.getEvent())){
					ObjectDrawServer serv = ObjectDrawServer.getInstance();
					serv.addObject(dro);
					dro.setColor(serv.getCurrentColor());
					dro.setTool(name);					
					dro = new DrawingObject();
				}else{//Doesn't matter what the event was as long as its not release
					String[] cords = act.getArguments().split(" ");
					dro.AddCoords(cords[0], cords[1]);
				}
			}
		}

	}

}
